<template>
  <div class="login-wrap">
    <el-form class="login-form"
             label-position="top"
             label-width="80px"
             :model="formdata">
      <h2>用户登录</h2>
      <el-form-item label="用户名">
        <el-input v-model="formdata.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="formdata.password"></el-input>
      </el-form-item>
      <el-button type="primary"
                 class="login-btn"
                 @click="login()">登陆</el-button>
    </el-form>
  </div>
</template>

<script>
import { getLoginMultidata } from '../../network/login'
export default {
  name: 'login',
  data () {
    return {
      formdata: {
        username: '',
        password: '',
      }
    }
  },
  methods: {

    // login () {
    //   getLoginMultidata(this.formdata).then(res => {
    //     console.log(res)
    //     console.log(this.formdata.username, this.formdata.password)
    //     if (this.formdata.username === 'admin' && this.formdata.password === "123456") {
    //       this.$router.push({ name: 'home' })
    //       this.$message.success('登录成功')
    //     } else if (this.formdata.username !== 'admin') {
    //       this.$message.warning('登录名不正确')
    //     } else if (this.formdata.username === 'admin' && this.formdata.password !== '123456') {
    //       this.$message.warning('密码不正确')
    //     }

    //   })
    // }
    //登陆请求
    async login () {
      const res = await getLoginMultidata(this.formdata)
      console.log(res)
      console.log(this.formdata.username, this.formdata.password)
      if (this.formdata.username === 'admin' && this.formdata.password === "123456") {
        localStorage.setItem('token', res.data.token)
        console.log(res.data.token)
        this.$router.push({ name: 'home' })
        this.$message.success('登录成功')
      } else if (this.formdata.username !== 'admin') {
        this.$message.warning('登录名不正确')
      } else if (this.formdata.username === 'admin' && this.formdata.password !== '123456') {
        this.$message.warning('密码不正确')
      }


    }

  }
}
</script>

<style scoped>
.login-wrap {
  height: 100%;
  background-color: #324152;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-wrap .login-form {
  width: 400px;
  background-color: #fff;
  border-radius: 5px;
  padding: 30px;
}
.login-wrap .login-btn {
  width: 100%;
}
</style>